/**
 * 请求形式
 * json
 * post
 *
 * */

import { baseUrl } from './config.js'

let axios = (url, method, data, head = {}) => {
  const app = getApp();
	let header = {
		'content-type': 'application/x-www-form-urlencoded',
    // token: (app.store.getStorage("token")) ? app.store.getStorage("token") : '',
		// ...head,
    token:'',
    platform: 'wechat_member',
	}
	return new Promise((resolve, reject) => {
		wx.request({
			url: baseUrl + url,
			method,
			header,
			data,
			success(res) {
				// if (res.code == 80003 && app.userInfo) {
				// 	const app = getApp()
				// 	app.login().then((res) => {
				// 		axiosJson(url, method, data, head)
				// 	})
				// 	return
				// }
				resolve(res.data)
			},
			fail(err) {
				reject(err)
			},
		})
	})
}

let axiosJson = (url, method, data, head = {}) => {
  const app = getApp();
	let header = {
		'content-type': 'application/json',
    // token: (app.store.getStorage("token")) ? app.store.getStorage("token") : '',
		// ...head,
	}
	return new Promise((resolve, reject) => {
		wx.request({
			url: baseUrl + url,
			method,
			header,
			data,
			success(res) {
				const app = getApp()
				// if (res.code == 80003 && app.userInfo) {
				// 	app.login().then((res) => {
				// 		axiosJson(url, method, data, head)
				// 	})
				// 	return
				// }
				resolve(res.data)
			},
			fail(err) {
				reject(err)
			},
		})
	})
}



export { axios, axiosJson }